#include "RingQueue.hpp"
#include <pthread.h>
#include <iostream>
#include <unistd.h>

void *productor(void *arg)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(arg);
    int num = 1000;
    while (true)
    {
        // sleep(1);
        rq->EnQueue(num);
        std::cout << "productor, Enqueue num : " << num << std::endl;
        num++;
    }
}

void *consumer(void *arg)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(arg);
    while (true)
    {
        sleep(1);
        int data;
        rq->Pop(&data);
        std::cout << "consumer, Pop data : " << data << std::endl;
    }
}

int main()
{
    RingQueue<int> rq;

    pthread_t td1[2], td2[3];

    pthread_create(td1, nullptr, productor, (void *)&rq);
    pthread_create(td1 + 1, nullptr, productor, (void *)&rq);

    pthread_create(td2, nullptr, consumer, (void *)&rq);
    pthread_create(td2 + 1, nullptr, consumer, (void *)&rq);
    pthread_create(td2 + 2, nullptr, consumer, (void *)&rq);

    pthread_join(td1[0], nullptr);
    pthread_join(td1[1], nullptr);

    pthread_join(td2[0], nullptr);
    pthread_join(td2[1], nullptr);
    pthread_join(td2[2], nullptr);

    return 0;
}